/*
 *
0
3
1
this : 0x562f516fb2c0
pcn: 0x562f516fb2c0

 */
#include <iostream>
using namespace std;
class Counter{
	private:
		int count;
	public:
		Counter(int count = 0){
			this->count = count;
		}
		Counter &add(void){
			++count;
			return *this;
		}
		void print(void){
			cout << count << endl;
		}
		void destroy(void){
			cout <<"this : " << this << endl;
			delete this; //销毁对象本身
		}
};
int main(void){
	
	//栈中新建对象
	Counter cnt;
	cnt.print();
	cnt.add().add().add();
	cnt.print();
	//由于不是堆中的对象，故不可调用delete
	//this : 0x7ffc5837485c
	//free(): invalid pointer
	//已放弃 (核心已转储)
	//cnt.destroy();

	//堆中新建对象
	Counter *pcn = new Counter;
	pcn->add();
	pcn->print();
	pcn->destroy();
	cout<<"pcn: " <<pcn <<endl;
	return 0;
}
